package org.opens.javaskill.jvm.classloader;

import org.junit.Test;

/**
 * @Date 2020/10/26 13:39
 * @Created by 99126
 */
public class JvmClassLoader {

    /**
     * 功能:
     * <p>验证根加载器加载的类的路径是从系统中获取的</p>
     */
    @Test
    public void test22() {
        System.out.println(System.getProperty("sun.boot.class.path"));
    }

    /**
     * 功能:
     * <p>验证扩展加载器加载的类的路径是从系统中获取的</p>
     */
    @Test
    public void test23() {
        System.out.println(System.getProperty("java.ext.dirs"));
    }

    /**
     * 功能:
     * <p>验证系统加载器加载的类的路径是从系统中获取的</p>
     */
    @Test
    public void test24() {
        System.out.println(System.getProperty("java.class.path"));
        System.out.println("---");
        System.out.println(System.getenv("classpath"));
    }

    /**
     * 功能:
     * <p>验证自定义的类是由AppClassLoader加载器完成的</p>
     */
    @Test
    public void test5() throws ClassNotFoundException {
        Class<?> aClass = Class.forName("org.opens.javaskill.jvm.classloader.JvmClassLoader");
        System.out.println(aClass.getClassLoader());
        System.out.println(aClass.getClassLoader().getParent());
        System.out.println(aClass.getClassLoader().getParent().getParent());
    }

    /**
     * 功能:
     * <p>验证自定义的类是由AppClassLoader加载器完成的</p>
     */
    @Test
    public void test6() throws ClassNotFoundException {
        Class<?> aClass = Class.forName("java.lang.Object");
        System.out.println(aClass.getClassLoader());
    }

}
